package de.hs.rm;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class BHGUIDesktop extends JFrame {
	
	public JLabel lbStatus;
	public JButton btStartServer;
	public JButton btStopServer;
	public JTextArea taLog;
	
	private final static String newline = "\n";
	
	public BHGUIDesktop()
	{
		super("BlueHid");
	    setSize(288,512);
	    setLocation(100,100);
	    this.setResizable(false);
	    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    
	    JPanel panel = new JPanel();
	    panel.setBackground(Color.white);
	    panel.setLayout(new GridBagLayout());
	    GridBagConstraints gbc = new GridBagConstraints();
	    this.add(panel);
	        
	    btStartServer = new JButton();
	    btStartServer.setText("start server");
	    gbc.fill = GridBagConstraints.HORIZONTAL;
	    gbc.weightx = 1.0;
	    gbc.gridx = 0;
	    gbc.gridy = 0;
	    //gbc.gridwidth = GridBagConstraints.REMAINDER;
	    panel.add(btStartServer, gbc);
	    
	    lbStatus = new JLabel(" ");
	    lbStatus.setOpaque(true);
	    
	    gbc.fill = GridBagConstraints.HORIZONTAL;
	    gbc.weightx = 1.0;
	    gbc.gridx = 1;
	    gbc.gridy = 0;
	    panel.add(lbStatus, gbc);
	    
	    btStopServer = new JButton();
	    btStopServer.setText("stop server");
	    gbc.fill = GridBagConstraints.HORIZONTAL;
	    gbc.weightx = 1.0;
	    gbc.gridx = 2;
	    gbc.gridy = 0;
	    //gbc.gridwidth = GridBagConstraints.REMAINDER;
	    panel.add(btStopServer, gbc);
	    
	    taLog = new JTextArea();
	    taLog.setLineWrap(true);
	    JScrollPane sbrTextArea = new JScrollPane(taLog);
	    sbrTextArea.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
	    gbc.fill = GridBagConstraints.BOTH;
	    gbc.weighty = 1.0;
	    gbc.gridx = 0;
	    gbc.gridy = 1;
	    gbc.gridheight = GridBagConstraints.REMAINDER;
	    gbc.gridwidth = GridBagConstraints.REMAINDER;
	    panel.add(sbrTextArea, gbc);
	    
	    setVisible(true);
	}
	
	public void updateTaLog(String logMsg)
	{
		taLog.append(logMsg + newline);
	}
	
	public void clearLog()
	{
		taLog.setText("");
	}

}
